// pages/index-inside-page/handleDanger/handleDanger.js
import {
    reqUpdateDanger
} from "../../../request/api"
import {
    showMsg
} from '../../../utils/config.js'
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        navHeight: app.globalData.navHeight + 'px', //头部距离
        radio: '1',
        handleContent: '',
        title: '隐患审核'
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            dangerInfo: JSON.parse(options.dangerInfo),
            title: JSON.parse(options.dangerInfo).status == 2  ? '隐患审核' : JSON.parse(options.dangerInfo).status == 3 ? '处理工单' : '处理审核'
        })
    },
    onChange(e) {
        console.log(e,"e");
        this.setData({
            radio: e.detail
        })
    },
    bindinput1(e) {
        console.log(e, "e");
        this.setData({
            handleContent: e.detail.value
        })
    },

    async onSave() {
        let handleResult;
        if (this.data.radio == 1) {
            if (this.data.dangerInfo.status == 3) {
                handleResult = '已修复'
            } else {
                handleResult = '通过'
            }
        } else {
            if (this.data.dangerInfo.status == 3) {
                handleResult = '未修复'
            } else {
                handleResult = '不通过'
            }
        }
        if(this.data.handleContent=='') return showMsg(this.data.dangerInfo.status==2?'审核意见不能为空':this.data.dangerInfo.status==3?'处理内容不能为空':'审核意见不能为空')
        let res = await reqUpdateDanger({
            auditId: this.data.dangerInfo.id,
            userId: app.globalData.userId,
            status: this.data.dangerInfo.status,
            handleContent: this.data.handleContent,
            handleResult,
            fileList: []
        })
        if (res.code !== 20000) return showMsg(res.message)
        wx.switchTab({
            url: '/pages/message/message',
        })
    }
})